package com.hl.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hl.dao.ShopDaoimpl;
import com.hl.pojo.PanghuShopGoods;
import com.hl.util.GeneralResult;
import com.hl.util.HttpUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/goods/addShopGoods")
public class ShopManageUpdate extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String json = HttpUtil.getJson(req);
        //获得java对象
        PanghuShopGoods panghuShopGoods = JSONObject.parseObject(json, PanghuShopGoods.class);
        //执行sql语句
        int num = 0;
        ShopDaoimpl dao = new ShopDaoimpl();
        num = dao.increaseGoods(panghuShopGoods);
        //返回数据给前端
        String msg = num>0?"操作成功":"操作失败";
        resp.setContentType("application/json;charset=utf-8");
        GeneralResult generalResult = new GeneralResult(200, msg);
        resp.getWriter().append(JSON.toJSONString(generalResult));
    }
}
